package com.movitech.mobile.cz.base.purchase.bizcontroller;

import com.baomidou.mybatisplus.plugins.Page;
import com.movitech.mobile.cz.base.modules.controller.RestReturnResult;
import com.movitech.mobile.cz.base.purchase.bizservice.OuterWorkFlowService;
import com.movitech.mobile.cz.base.purchase.bizservice.WorkFlowService;
import com.movitech.mobile.cz.base.purchase.bizvo.DealRequestVO;
import com.movitech.mobile.cz.base.purchase.bizvo.InvitationDetailResponse;
import com.movitech.mobile.cz.base.purchase.bizvo.ManageCenterRequestVO;
import com.movitech.mobile.cz.base.purchase.bizvo.outer.*;
import com.movitech.mobile.cz.base.purchase.entity.ext.ExtWFlowFormExtMng;
import com.movitech.mobile.cz.base.purchase.service.WFlowFormSupplierEntryService;
import com.movitech.mobile.cz.base.supplier.entity.SMyDeals;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
/**
 * Created by robie.cao on 2018/4/25.
 */
@RestController
@RequestMapping("/v1/outerformflow")
@Api(value = "采购流程接口", description = "采购流程接口")
public class OuterWorkFlowController {

    @Autowired
    private OuterWorkFlowService outerWorkFlowService;

    @Autowired
    private WorkFlowService workFlowService;
    @Autowired
    private WFlowFormSupplierEntryService wFlowFormSupplierEntryService;


    @PostMapping("/getBidManageData")
    @ApiOperation(
            value = "招标管理列表",
            notes = "招标管理列表"
    )
    public RestReturnResult<Page<ExtWFlowFormExtMng>> getBidManageData(@RequestBody BidManageReqVo bidManageReqVo) {
        RestReturnResult restResult = RestReturnResult.success();
        Page<ExtWFlowFormExtMng> page = new Page<>();
        page.setCurrent(bidManageReqVo.getPageRequestVO().getPageNumber());
        page.setSize(bidManageReqVo.getPageRequestVO().getPageSize());
        restResult.setData( outerWorkFlowService.getBidManageData(page,bidManageReqVo));
        return restResult;
    }

    @GetMapping("/purchaseItemDetail")
    @ApiOperation(
            value = "流程节点详情",
            notes = "流程节点详情"
    )
    public RestReturnResult<BidItemDetailVo> purchaseItemDetail(@RequestParam String id) throws Exception {
        RestReturnResult restResult = RestReturnResult.success();
        restResult.setData(outerWorkFlowService.purchaseItemDetail(id));
        return restResult;
    }

    @PostMapping("/dealsList")
    @ApiOperation(value = "我的代办列表", notes = "我的代办列表")
    public RestReturnResult<SMyDeals>  dealsList(@RequestBody DealListReqVo dealListReqVo) {
        RestReturnResult restResult = RestReturnResult.success();
        restResult.setData(outerWorkFlowService.selectMyDealList(dealListReqVo));
        return restResult;
    }

    @GetMapping("/invitationDetail")
    @ApiOperation(value = "邀请函详情", notes = "邀请函详情")
    public RestReturnResult<InvitationDetailResponse>  invitationDetail(@RequestParam String formId) {
        RestReturnResult restResult = RestReturnResult.success();
        restResult.setData(outerWorkFlowService.invitationDetail(formId));
        return restResult;
    }

    @PostMapping("/invitationReply")
    @ApiOperation(value = "邀请函回复", notes = "邀请函回复")
    public RestReturnResult  invitationReply(@RequestBody DealRequestVO vo) {
        RestReturnResult restResult = RestReturnResult.success();
        outerWorkFlowService.invitationReply(vo);
        return restResult;
    }


    @GetMapping("/invitationReplyTest/{formId}/{supplierId}/{flag}")
    @ApiOperation(value = "邀请函回复Test", notes = "邀请函回复Test")
    public RestReturnResult  invitationReplyTest(@PathVariable String formId,@PathVariable(value = "supplierId")String supplierId,@PathVariable Integer flag) {
        RestReturnResult restResult = RestReturnResult.success();
        wFlowFormSupplierEntryService.updateReturnStatusByFormIdAndSupplierId(formId, supplierId, flag);
        return restResult;
    }

    @PostMapping("/bidFile/list")
    @ApiOperation(value = "标书下载列表", notes = "标书下载列表")
    public RestReturnResult<BidFileDownRspVo>  bidFileList(@RequestBody BidFileDownReqVo vo) {
        RestReturnResult restResult = RestReturnResult.success();
        restResult.setData(outerWorkFlowService.bidFileList(vo));
        return restResult;
    }

    @GetMapping("/askAndAnswer/list")
    @ApiOperation(value = "答疑补遗列表", notes = "答疑补遗列表")
    public RestReturnResult<AskQuestionRspVo>  askAndAnswerList(@RequestParam String formId) {
        RestReturnResult restResult = RestReturnResult.success();
        restResult.setData(outerWorkFlowService.askAndAnswerList(formId));
        return restResult;
    }

    @GetMapping("/inquiringBid/list")
    @ApiOperation(value = "询标回复列表", notes = "询标回复列表")
    public RestReturnResult<InquiringBidRspVo>  inquiringBidList(@RequestParam String formId) {
        RestReturnResult restResult = RestReturnResult.success();
        restResult.setData(outerWorkFlowService.inquiringBidList(formId));
        return restResult;
    }

    @PostMapping("/inquiringBid/submit")
    @ApiOperation(value = "提交询标回复", notes = "提交询标回复")
    public RestReturnResult<InquiringBidRspVo>  inquiringBidSubmit(@RequestBody InquiringBidReqVo inquiringBidReqVo) {
        RestReturnResult restResult = RestReturnResult.success();
        outerWorkFlowService.inquiringBidSubmit(inquiringBidReqVo);
        return restResult;
    }

    @GetMapping("/noticeAndThanks/list")
    @ApiOperation(value = "中标通知书和感谢信", notes = "中标通知书和感谢信")
    public RestReturnResult<NoticeAndThanksRspVo>  noticeAndThanksList(@RequestParam String formId) {
        RestReturnResult restResult = RestReturnResult.success();
        restResult.setData(outerWorkFlowService.noticeAndThanksList(formId));
        return restResult;
    }


    @PostMapping("/questions/submit")
    @ApiOperation(value = "质疑文件提交", notes = "质疑文件提交")
    public RestReturnResult questionsSumit(@RequestBody QuestionsReqVo vo) {
        RestReturnResult restResult = RestReturnResult.success();
        if(outerWorkFlowService.checkQuestionTime(vo)){
            outerWorkFlowService.questionsSumit(vo);
        }else{
            restResult = RestReturnResult.error();
            restResult.setMsg("当前已过质疑时间，不可再提交！");
        }
        return restResult;
    }

    @PostMapping("/backBid/detail")
    @ApiOperation(value = "回标(包含所有类型的回标以及历史查询)", notes = "回标")
    public RestReturnResult<BackBidRspVo> backBidDetail(@RequestBody BackBidReqVo vo) {
        RestReturnResult restResult = RestReturnResult.success();
        restResult.setData(outerWorkFlowService.backBidDetail(vo));
        return restResult;
    }

    @PostMapping("/backBid/submit")
    @ApiOperation(value = "提交回标", notes = "提交回标")
    public RestReturnResult<BackBidRspVo> backBidSubmit(@RequestBody BackBidSubmitVo vo) {
        RestReturnResult restResult = RestReturnResult.success();
        outerWorkFlowService.backBidSubmit(vo);
        return restResult;
    }


    @PostMapping("/bidFile/down")
    @ApiOperation(value = "附件下载(所有附件 单个下载)", notes = "附件下载")
    public RestReturnResult  bidFileDown(@RequestBody AttachDownVo vo) {
        RestReturnResult restResult = RestReturnResult.success();
        restResult.setData(outerWorkFlowService.bidFileDown(vo));
        return restResult;
    }


//    @GetMapping("/getBidingDoc/{formId}")
//    @ApiOperation(
//            value = "获取招标投标详情",
//            notes = "获取招标投标详情",
//            response = WFlowForm.class
//    )
//    public RestReturnResult getBidingDoc(@PathVariable String formId) {
//        RestReturnResult restResult = RestReturnResult.success();
//        outerWorkFlowService.getBidingDoc(formId);
//        return restResult;
//    }
//
//    @GetMapping("/getPlanInvitation/{formId}")
//    @ApiOperation(value = "获取邀请函信息", notes = "获取邀请函信息")
//    public RestReturnResult getPlanInvitation(HttpServletRequest request, @PathVariable String formId){
//        RestReturnResult restResult = RestReturnResult.error();
//        restResult=outerWorkFlowService.getPlanInvitation(request,formId);
//        return restResult;
//    }
//
//    @GetMapping("/replyInvitation")
//    @ApiOperation(value = "回复邀请函", notes = "回复邀请函")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name="formId",value="formId",dataType="string", paramType = "query"),
//            @ApiImplicitParam(name="actionType",value="0 不参与 1参与",dataType="Integer", paramType = "query")})
//    public RestReturnResult replyInvitation(HttpServletRequest request, String formId,Integer actionType){
//        RestReturnResult restResult = RestReturnResult.error();
//        restResult=outerWorkFlowService.replyInvitation(request,formId,actionType);
//        return restResult;
//    }
//
//
//    @GetMapping("/getBidAttach/{formId}")
//    @ApiOperation(value = "获取发标文件", notes = "获取发标文件")
//    public RestReturnResult getBidAttach(@PathVariable String formId,HttpServletRequest request){
//        RestReturnResult restResult = RestReturnResult.error();
//        return restResult;
//    }
//
//    @PostMapping("/questionBid")
//    @ApiOperation(value = "外网质疑", notes = "外网质疑")
//    public RestReturnResult questionBid(HttpServletRequest request,@RequestBody QuestionBidRequestVO questionBidRequestVO){
//        RestReturnResult restResult = RestReturnResult.error();
//        restResult=outerWorkFlowService.questionBid(request,questionBidRequestVO);
//        return restResult;
//    }

    @GetMapping("/managementCenter")
    @ApiOperation(value = "管理中心", notes = "管理中心")
    public RestReturnResult managementCenter(HttpServletRequest request){
        RestReturnResult restResult = RestReturnResult.error();
        restResult=outerWorkFlowService.managementCenter(request);
        return restResult;
    }

    @PostMapping("/managementCenterList")
    @ApiOperation(value = "管理中心列表", notes = "管理中心列表")
    public RestReturnResult managementCenterList(HttpServletRequest request,@RequestBody ManageCenterRequestVO manageCenterRequestVO){
        RestReturnResult restResult = RestReturnResult.error();
        restResult=outerWorkFlowService.managementCenterList(request,manageCenterRequestVO);
        return restResult;
    }

}
